<template>
  <div class="app-found" style="margin: 0 !important;">
    <el-col style="background: #fff;padding: 20px 50px">
      <el-col>
        <div class="else-message">下单仓库与配送地址</div>
        <el-form ref="listMessage" :inline="true" :model="listMessage" :rules="rules" class="demo-form-inline" style="display: block;">
          <el-col style="display: flex">
            <el-form-item label="下单仓库" label-width="120px" required class="commonForm" style="width: 70%;display: flex;margin-bottom: 1px!important;">
              <el-form-item prop="city" style="width: 30%">
                <el-select v-model="deptName" placeholder="城市" size="medium" style="width: 100%;" @change="cityclick">
                  <el-option v-for="(house,citykey) in cityselect" :key="citykey" :label="house.deptName" :value="{value:house.id,label:house.deptName}"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item prop="wareHouse" style="width: 30%">
                <el-select v-model="listMessage.wareHouse" placeholder="总仓" size="medium" style="width: 100%;margin-left: 5px;" @visible-change="wareclick(listMessage.wareHouse)">
                  <el-option v-for="(house,ware) in citylist" :key="ware" :label="house.deptName" :value="house.id">
                    <span @click="getwareHouseOpen(house.deptName)" style="display: inline-block;width: 100%;padding: 0 20px;">{{ house.deptName }}</span>
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item prop="abbr" class="wareHouse" style="width: 30%">
                <el-select v-model="listMessage.abbr" placeholder="分仓" @change="getwarehouseId" size="medium" style="width: 100%;margin-left: 5px;">
                  <el-option v-for="(house,ware) in abbrlist" :key="ware" :label="house.name" :value="{value:house.id,label:house.name}">
                  <!-- <el-option v-for="(house,ware) in abbrlist" :key="ware" :label="house.name" :value="house.name"> -->
                    <!-- {{ house.name }} -->
                    <!-- <span :data-warehouseId="house.id" @click="getwarehouseId(house.id)" style="display: inline-block;width: 100px;padding: 0 20px;margin-left: -20px;">{{ house.name }}</span> -->
                  </el-option>
                </el-select>
              </el-form-item>
            </el-form-item>
          </el-col>
          <el-col>
            <div style="position: relative" class="getadressDetailDiv">
              <el-form-item label="定位" label-width="115px" style="margin-top: -6px;">
                <el-input
                  type="textarea"
                  id="getDetail"
                  v-model.trim="listMessage.address1"
                  maxlength="54"
                  @focus="SearchAddress"
                  @input="SearchAddress"
                  @keyup.up.native="selectTopItem()"
                  @keyup.down.native="selectBottomItem()"
                  @keydown.enter.native="getlnglat(currentIndex)"
                  autocomplete="off"
                  placeholder="请输入地址"
                  size="medium"
                  autosize
                  show-word-limit
                  style="width: 530px;"
                ></el-input>
              </el-form-item>
              <!-- v-if="addressFlag" -->
              <div
                id='mapDiv'
                class="adressDetailDiv"
              >
                <ul
                  v-show="addressFlag || isaddressFlag"
                  id='mapDiv'
                  class="adressDetail"
                >
                  <li
                    v-for="(addressitem,index) in addressList.slice((currentPage-1)*pagesize,currentPage*pagesize)"
                    :key="index"
                    :class="currentIndex == index ? 'addressActive' : ''"
                    id='mapDiv'
                    @mouseover="changeColor(index)"
                    @mouseout="loseColor(index)"
                    @click="getlnglat(index)"
                  >
                    <!-- @mouseover="changeColor($event)" -->
                    <!-- @mouseout="loseColor($event)" -->
                    <p id='mapDiv' class="el-icon-location-information">{{ addressitem.name }}</p>
                    <p id='mapDiv' class="el-icon-location-information">地址：<span v-if="addressitem.address.length > 0 ? true : false">{{ addressitem.address }}</span></p>
                    <p id='mapDiv' class="el-icon-location-information">城市：<span v-if="addressitem.district !== ''? true : false">{{ addressitem.district }}</span></p>
                  </li>
                  <el-pagination
                    id='mapDiv'
                    v-show="addressFlag || isaddressFlag"
                    background
                    :current-page.sync="currentPage"
                    layout="prev, pager, next, sizes, total, jumper"
                    :page-sizes="[5, 10, 15, 20]"
                    :page-size.sync="pagesize"
                    :total="addressList.length"
                    @current-change="handleCurrentChange"
                    @size-change="handleSizeChange"
                    style="margin-top: 5px 0;"
                  >
                  </el-pagination>
                </ul>
              </div>
            </div>
            <el-form-item label="地址" label-width="115px" prop="address2">
              <el-input
                type="textarea"
                v-model.trim="listMessage.address2"
                placeholder="请输入楼层、房号"
                maxlength="54"
                onkeyup="value=value.replace(/\s+/g, '')"
                onafterpaste="value=value.replace(/\s+/g, '')"
                show-word-limit
                autosize
                size="medium"
                style="width: 530px;"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <div class="amap-page-container">
              <div class="amap" style="height: 500px;">
                <el-amap vid="amapDemo" id="amapDemo" :center="mapCenter" :zoom="12" class="amap-demo" v-cloak>
                  <el-amap-marker v-for="(marker,index) in markers" :key="index" :position="marker"></el-amap-marker>
                </el-amap>
                <div id="panel"></div>
              </div>
            </div>
          </el-col>
          <div class="else-message">商品信息</div>
          <el-col v-if="noEditCakeFlag">
            <el-col style="margin: 0 0 10px 119px;line-height: 80px;">
              还没有蛋糕，请点击下面“编辑蛋糕”按钮选择蛋糕
            </el-col>
            <el-col style="margin: 0 0 30px 119px;">
              <el-button type="primary" @click="openEditCake">编辑蛋糕</el-button>
            </el-col>
          </el-col>
          <el-dialog
            title
            :visible.sync="openEditCakeFlag"
            :before-close="handleCakeClose"
            center
            :append-to-body="true"
            :lock-scroll="false"
            width="70%"
            z-index="2007"
          >
            <el-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="商品" name="first">
                <el-col style="margin-top: 1%;">
                  <div class="order-message" style="height: 35px;width: 100%;">
                    <el-col :span="10">
                      <el-input v-model="cakeInput" clearable placeholder="请输入商品名称" size="small"></el-input>
                    </el-col>
                    <el-col :span="5" style="margin-left: 15px;">
                      <el-button icon="el-icon-search" type="primary" size="small" @click="open()">查询</el-button>
                    </el-col>
                  </div>
                  <el-scrollbar class="page-component__scroll"  v-loading="Loading" style="width: 100%;height: 600px;">
                    <div v-for="(item, index) in list" :key="index" class="order-list">
                      <div class="order-list-item">
                        <div class="orderfound-header-area">
                          <div class="order-header" style="display: flex;justify-content: space-between;padding-top: 10px">
                            <div class="order-num" style="margin-right: 35px;">
                              <span>{{ item.name }}</span>
                              <!-- <i></i> -->
                            </div>
                            <div class="order-state"></div>
                            <el-tag type="danger" style="margin-right: 50%;">{{ item.categoryName }}</el-tag>
                          </div>
                        </div>
                        <div class="order-user-area" style="display: flex">
                          <div style="width: 100px;height: 80px;margin-right: 10px;">
                            <img style="width: 100px;height: 80px;" :src="item.mainPic" alt="">
                          </div>
                          <div style="margin-left: 10px;width: 86%;">
                            <div class="user-phone-address">
                              <div style="display: flex;">
                                <el-col style="width: 75%">
                                  <h3 style="margin: 0 0 9px 0;padding-bottom: 5px;border-bottom: 1px solid #C0C4CC;width: 70px;text-align: center;">规格</h3>
                                  <div
                                    v-for="(cakeing,key) in item.goodsSkuVOS"
                                    :key="key"
                                    style="margin-bottom: 5px;"
                                  >
                                    <el-button
                                      @click="choiceCheck(cakeing,index,$event)"
                                    >{{ cakeing.specs }}</el-button>
                                  </div>
                                </el-col>
                                <el-col style="width: 25%">
                                  <h3 style="margin: 0 0 9px 0;padding-bottom: 5px;border-bottom: 1px solid #C0C4CC;width: 70px;text-align: center;">价格</h3>
                                  <div
                                    v-for="(cakeing,key) in item.goodsSkuVOS"
                                    :key="key"
                                    style="line-height: 40px;margin-bottom: 5px;"
                                  >
                                    <span
                                      style="display: inline-block;text-align: center;"
                                    ><i class="price-style">{{ (cakeing.price/100).toFixed(2) }}</i>元</span>
                                  </div>
                                </el-col>
                              </div>
                              <el-button type="primary" @click="addEditCake(item)">添加</el-button>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <pagination v-show="shopTotal>0" :total="shopTotal" :page.sync="shoplist.page" :limit.sync="shoplist.size"
                      @pagination="getCakeList" />
                    <!-- <el-pagination
                      background
                      :current-page.sync="currentPage"
                      layout="prev, pager, next, sizes, total, jumper"
                      :page-sizes="[5, 10, 15, 20]"
                      :page-size.sync="pagesize"
                      :total="list.length"
                      @current-change="handleCurrentChange"
                      @size-change="handleSizeChange"
                      style="margin-top: 5px 0;"
                    >
                    </el-pagination> -->
                  </el-scrollbar>
                </el-col>
              </el-tab-pane>
              <el-tab-pane label="备款蛋糕" name="second">
                <el-col style="margin-top: 1%;">
                  <div class="order-message" style="width: 100%;height: 35px;">
                    <el-col :span="10">
                      <el-input v-model="input" clearable placeholder="请输入蛋糕名称" size="small"></el-input>
                    </el-col>
                    <el-col :span="5" style="margin-left: 15px;">
                      <el-button icon="el-icon-search" type="primary" size="small" @click="ProvisionsGoodsPageopen()">查询</el-button>
                    </el-col>
                  </div>
                  <el-scrollbar class="page-component__scroll" style="width: 100%;height: 600px;">
                    <div v-loading="Loading" v-for="(cakeMessage, index) in getGoodsPageList" :key="index" class="order-list">
                      <div class="order-list-item" style="padding: 10px 15px 0 0;">
                        <div class="orderfound-header-area">
                          <div class="order-header">
                            <div class="order-num" style="width: fit-content;">
                              <span>{{ cakeMessage.goodsName }}</span>
                              <!-- <i></i> -->
                            </div>
                            <div class="order-state"></div>
                          </div>
                        </div>
                        <div class="order-user-area" style="display: flex">
                          <div style="margin-left: 10px;width: 100%;">
                            <div class="user-phone-address">
                              <div style="display: flex;">
                                <el-col style="width: 65%">
                                  <p class="phone-title">蛋糕旧单号：<span style="color: #000">{{ cakeMessage.xmbzNo }}</span></p>
                                  <p class="phone-title">蛋糕明细编码：<span style="color: #000">{{ cakeMessage.orderDetailId }}</span></p>
                                  <p class="phone-title">规格：<span style="color: #000">{{ cakeMessage.goodsSpecs }}</span></p>
                                  <div style="display: flex;justify-content: space-between;">
                                    <p class="phone-title">价格：<i class="price-style">{{ (cakeMessage.cakePrice/100).toFixed(2) }}</i></p>
                                    <p class="phone-title">数量：<span style="color: #000">{{ cakeMessage.cakeNum }}</span></p>
                                  </div>
                                  <div style="display: flex;justify-content: space-between;">
                                    <p class="phone-title">城市：<span style="color: #000">{{ cakeMessage.cityName }}</span></p>
                                    <p class="phone-title">总仓：<span style="color: #000">{{ cakeMessage.mainWarehouse }}</span></p>
                                    <p class="phone-title">分仓：<span style="color: #000">{{ cakeMessage.branchWarehouse }}</span></p>
                                  </div>
                                </el-col>
                              </div>
                              <div style="display: flex;justify-content: flex-end;margin-right: 50px;">
                                <el-button type="primary" @click="choiceGoodsCheck(cakeMessage)">添加</el-button>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <pagination v-show="GoodsPageTotal>0" :total="GoodsPageTotal" :page.sync="getProvisionsGoodsPageQuery.page" :limit.sync="getProvisionsGoodsPageQuery.size"
                      @pagination="getProvisionsGoodsPageList" />
                  </el-scrollbar>
                </el-col>
              </el-tab-pane>
              <el-tab-pane label="已选商品" name="third">
                <el-col style="margin-top: 1%;">
                  <el-scrollbar class="page-component__scroll" style="height: 600px;">
                    <div>
                      <table v-for="(value,index) in tableData" :key="index" style="margin-bottom: 20px;width: 98%;" class="order-list">
                        <tr>
                          <td>商品名称</td>
                          <td>商品规格</td>
                          <td>价格</td>
                          <td>现价</td>
                          <td style="position: relative;">
                            商品数量
                            <span v-if="value.ProvisionsFlag == 2 ? true : false" style="position: absolute;right: 0;top: 0;width: 0;height: 0;border-top: 60px solid #CCC;border-left: 60px solid transparent;">
                              <i style="position: absolute;top: -55px;right: 15px;color: #fff;transform: rotate(-49deg);">备款</i>
                            </span>
                          </td>
                        </tr>
                        <tr>
                          <td style="width: 8rem;">{{ value.goodsName }}</td>
                          <td style="width: 6rem;">{{ value.specs }}</td>
                          <td style="width: 4rem;">{{ (value.price/100).toFixed(2) }}</td>
                          <td style="width: 4rem;">{{ (value.price/100).toFixed(2) }}</td>
                          <td style="width: 14rem;">
                            <el-button
                              v-show="value.reserveCakeFlag == true ? true : false"
                              size="mini"
                              @click="handleEdit(index,$event)"
                            >添加</el-button>
                            <span style="width: 40px;display: inline-block;">{{ value.num }}</span>
                            <el-button
                              v-show="value.reserveCakeFlag == true ? true : false"
                              size="mini"
                              type="danger"
                              @click="handleDelete(index,$event)"
                            >减少</el-button>
                          </td>
                        </tr>
                        <tr>
                          <td colspan="4">
                            <span style="color: red;font-size: 15px;font-weight: 600;">祝福语</span>
                            <el-input v-model.trim="value.blessings" type="textarea" placeholder="请输入祝福语" @input="getBlessing(value.wishing)" maxlength="16" show-word-limit autosize></el-input>
                          </td>
                          <td style="color: red;font-size: 15px;font-weight: 600;">
                            <div style="display: flex;justify-content: space-around;line-height: 2;">
                              总价：<span id="singletonPrice">{{ (value.getPrice/100).toFixed(2) }}</span>
                              <el-button size="small" :data-id="value.id" @click="cleanOrder(index,$event)">清除</el-button>
                            </div>
                          </td>
                        </tr>
                      </table>
                      <div style="display: flex;flex-direction: column;align-items: flex-end;">
                        <p style="color: red;font-size: 20px;font-weight: 700;margin-right: 20px;">所选商品总价：{{ (sumPrice/100).toFixed(2) }}</p>
                      </div>
                      <el-form-item style="display: flex;flex-direction: column;align-items: flex-end;">
                        <el-button type="primary" @click="onAddSumbit()" style="margin-right: 20px;">提交</el-button>
                      </el-form-item>
                    </div>
                  </el-scrollbar>
                </el-col>
              </el-tab-pane>
            </el-tabs>
          </el-dialog>
          <el-col v-if="!noEditCakeFlag" style="width: 100%;margin: 0 70px 30px 79px;">
            <ul class="EditCake">
              <li
                v-for="(itemcake,indexcake) in tableCakeData"
                :key="indexcake"
                class="EditCakeLi">
                <p class="EditCakeLine"><span>蛋糕：</span><span>{{ itemcake.goodsName}}</span></p>
                <p class="EditCakeLine"><span>规格：</span><span>{{ itemcake.goodsSpecs }}</span></p>
                <div class="EditCakeLine" style="display: flex;">
                  <div style="width: 30%;"><span>价格：</span><i class="cak">{{ (itemcake.price/100).toFixed(2) }}</i>元</div>
                  <div style="width: 30%;"><span>数量：</span><span>{{ itemcake.num }}</span></div>
                </div>
                <!-- <p class="EditCakeLine"><span>状态：</span><span>{{ itemcake.goodsSpecs }}</span></p> -->
                <p class="EditCakeLine"><span>祝福语：</span><span>{{ itemcake.blessings?itemcake.blessings:'' }}</span></p>
              </li>
            </ul>
            <el-col style="margin: 0 0 30px 119px;">
              <el-button type="primary" @click="openEditCake">编辑蛋糕</el-button>
            </el-col>
          </el-col>
          <div class="else-message">其他信息</div>
          <el-col>
            <el-form-item label="订单总价" label-width="130px" prop="totalPrice" style="width: 37%;display: flex;">
              <el-input v-model.trim="listMessage.totalPrice" placeholder="请输入订单总价" oninput="value=value.replace(/[^\d.]/g,'')" maxlength="10" size="medium" style="width: 210px"></el-input>
            </el-form-item>
          </el-col>
          <el-col></el-col>
          <div class="else-message">其他信息</div>
          <el-col style="display: flex;">
            <el-form-item label="收货人" label-width="130px" prop="name" style="width: 37%;display: flex;">
              <el-input v-model.trim="listMessage.name" placeholder="请输入收货人" maxlength="10" size="medium" style="width: 210px"></el-input>
            </el-form-item>
            <el-form-item label="手机号码" label-width="130px" prop="phone" style="width: 37%;display: flex;">
              <el-input v-model.trim="listMessage.phone" placeholder="请输入手机号码" maxlength="11" size="medium" style="width: 210px"></el-input>
            </el-form-item>
          </el-col>
          <el-col style="display: flex;">
            <el-form-item label="渠道类别" label-width="130px" prop="channelType" style="width: 37%;display: flex;" class="commonForm">
              <el-select v-model="listMessage.channelType" @keydown.native="channelFilter" clearable filterable placeholder="请选择渠道类别" size="medium" style="width: 210px">
                <el-option v-for="(channelitem,channel) in channelTypellist" :key="channel" :label="channelitem.channelName" :value="channelitem.channelKey">
                  <span :data-id="channelitem.id" style="display: block;width: 100%;padding: 0 20px;margin-left: -20px;" @click="getchannelTypeId($event)">{{ channelitem.channelName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="渠道" label-width="130px" prop="channer" style="width: 37%;display: flex;" class="commonForm">
              <el-select v-model="listMessage.channer" @keydown.native="channelFilter" @visible-change="getchannelList" clearable filterable placeholder="请选择渠道" size="medium" style="width: 210px">
                <el-option v-for="(channelitem,channel) in channerllist" :key="channel" :label="channelitem.channelName" :value="channelitem.channelKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col style="display: flex;"> -->
          <el-form-item label="平台单号" label-width="130px" class="commonForm" style="width: 37%;display: flex;">
            <el-input
              v-model="listMessage.platformOrderId"
              @input="accountInput"
              placeholder="请输入平台单号"
              type="textarea"
              maxlength="25"
              onkeyup="value=value.replace(/\s+/g, '')"
              onafterpaste="value=value.replace(/\s+/g, '')"
              show-word-limit
              autosize
              size="medium"
              style="width: 210px"
            ></el-input>
          </el-form-item>
          <el-form-item label="配送时间" label-width="130px" required class="selectTime" style="display: flex;margin-top: 30px !important;margin-bottom: 0px !important;">
            <el-form-item prop="deliveryStartTime">
              <el-date-picker
                type="date"
                size="medium"
                placeholder="选择日期"
                v-model="listMessage.deliveryStartTime"
                :picker-options="pickerOptionsStart"
                :clearable="false"
                value-format="yyyy-MM-dd "
                format="yyyy-MM-dd "
                style="width: 100%;"
              ></el-date-picker>
            </el-form-item>
            <div class="line" :span="1" style="margin-right: 10px;">-</div>
            <el-form-item prop="date2">
              <selecttime
                ref="getdeliveryTime"
                v-bind:OrderStartTime="OrderStartTime"
                v-bind:OrderEndTime="OrderEndTime"
                v-bind:OrderTimeFlag="OrderTimeFlag"
                v-bind:deliveryTime="listMessage.deliveryStartTime"
              ></selecttime>
            </el-form-item>
          </el-form-item>
          <!-- <div v-if="selectTimeFlag"></div> -->
            <!-- <el-form-item label="配送时间" label-width="130px" required class="el-form-item-class" style="display: flex;width: 37%;">
              <span v-if="listMess.deliveryStartTime">{{ listMess.deliveryStartTime.slice(0,16) }}~{{ listMess.deliveryEndTime.slice(11,16) }}</span>
              <el-button type="primary" plain @click="deliveryTimeOpen">选择配送时间</el-button>
            </el-form-item> -->
            <!-- <el-dialog
              title
              :visible.sync="deliveryTimeFlag"
              center
              :before-close="handleClose"
              :append-to-body="true"
              :lock-scroll="false"
              width="95%"
              z-index="2007"
            >
              <deliveryTime
                ref="getdeliveryTime"
                v-bind:getdeliveryStartTime="getdeliveryStartTime"
                v-loading="Loading"
                v-bind:timelist="timelist"
                v-bind:warehouseLoadList="warehouseLoadList"
                v-bind:checkedlist="checkedlist"
                v-bind:idList="idList"
                v-bind:orderStartEndTime="orderStartEndTime"
                @getgetSurplusWarehouseLoadList="getgetSurplusWarehouseLoadList"
              ></deliveryTime>
              <el-col class="selectTimesubmit">
                <el-button type="primary" @click="selectSubmit">完成</el-button>
                <el-button type="primary" plain @click="cancelSelectTime" style="margin-left: 65px;">取消</el-button>
              </el-col>
            </el-dialog> -->
          <!-- </el-col> -->
          <el-form-item label="客服备注" label-width="130px" prop="customerServiceNotes" style="width: 77%;display: flex;">
            <el-input v-model.trim="listMessage.customerServiceNotes" type="textarea" maxlength="50" show-word-limit autosize placeholder="请输入客服备注" size="medium" style="width: 510px;"></el-input>
          </el-form-item>
          <el-form-item label="配送备注" label-width="130px" prop="deliveryRemark" class="commonForm" style="width: 77%;display: flex;">
            <el-input v-model.trim="listMessage.deliveryRemark" type="textarea" maxlength="50" show-word-limit autosize placeholder="请输入配送备注" size="medium" style="width: 510px;"></el-input>
          </el-form-item>
          <el-form-item label="平台门店" label-width="130px" prop="storeInfo" style="width: 77%;display: flex;">
            <el-input v-model.trim="listMessage.storeInfo" type="textarea" maxlength="30" show-word-limit autosize placeholder="请输入门店信息" size="medium" style="width: 510px;"></el-input>
          </el-form-item>
          <el-form-item label="生产备注" label-width="130px" prop="productRemark" class="commonForm" style="width: 77%;display: flex;">
            <el-input v-model.trim="listMessage.productRemark" type="textarea" maxlength="50" show-word-limit autosize placeholder="请输入生产备注" size="medium" style="width: 510px"></el-input>
          </el-form-item>
          <el-form-item label="客户备注" label-width="130px" prop="customerRemark" style="width: 77%;display: flex;">
            <el-input v-model.trim="listMessage.customerRemark" type="textarea" maxlength="50" show-word-limit autosize placeholder="请输入客户备注" size="medium" style="width: 510px"></el-input>
          </el-form-item>
          <el-col style="display: flex;justify-content: center;">
            <el-button  type="primary" @click="onSubclick('listMessage')" :disabled="foundOrderFlag == true ? true : false" style="margin-right: 20px;">立即创建</el-button>
            <!-- <el-button @click="cancelOrder('listMessage')">取消订单</el-button> -->
          </el-col>
        </el-form>
      </el-col>
    </el-col>
   <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
  </div>
</template>
<script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=57358ac872e8f834962f8aa7072c7bfe&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>
<script>
import {
  shopList,
  citySelect,
  createOrder,
  getMainWarehouseList,
  getSeparateWarehouseList,
  getOrderChannelList,// 渠道
  getWarehousesByDeptIds,
  getWarehouseName, // 根据经度纬度，返回分仓总仓名称
  getProvisionsGoodsPage, // 备款商品分页列表
  createOrderByProvisions, // 创建订单添加备款商品后，判断是否更新原订单状态
  judgeGoodsClose, // 判断当前商品是否关闭
  getSurplusWarehouseLoadList, // 仓库剩余负荷列表
  getOrderChannelTypeList, // 渠道类别列表
} from "@/api/createOrder";
import { shopSize } from "@/api/pending";
import { getWarehouseList } from "@/api/warehouse";
import deliveryTime from '@/components/foundorder/deliverytime';
import Pagination from "@/components/Pagination"; // 分页
import selecttime from "@/components/foundorder/selecttime"; // 配送时间组件
export default {
  components: {
    deliveryTime,
    Pagination,
    selecttime
  },
  data() {
    var validPhone = (rule, value, callback) => {
      const reg = /^1[0-9][0-9]\d{8}$/;
      if(!value) {
        callback(new Error('请输入电话号码'));
      } else if(!reg.test(value)) {
        callback(new Error('请输入正确的电话号码'));
      } else {
        callback();
      }
    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入地址'));
      } else {
        this.listMessage.address2 = value.replace(/\s+/g, '');
        callback();
      }
    };
    var checkData = (rule, value, callback) => {
      if (value) {
        if (/[\u4E00-\u9FA5]/g.test(value)) {
          this.listMessage.totalPrice = '';
          callback(new Error('编码不能输入汉字!'));
        } else {
          callback();
        }
      }
      callback();
    };
    return {
      deptId:'',
      deptName:'',
      orderStartEndTime: '',
      // 创建订单请求表单
      listMessage: {
        receiverAddress: "西湖区骆家庄西苑一区",
        channel: 1,    
        name: '',
        phone: '',
        wareHouse: '',
        abbr: '',
        mainWarehouse: "滨江区",
        branchWarehouse: "YB",
        platformOrderId: '',
        city: JSON.parse(window.localStorage.getItem("saber-areaId")).content,
        channelType: '',// 渠道类别
        channer: '',// 渠道
        // deptId: JSON.parse(window.localStorage.getItem("saber-areaId")).content,
        customerNotes: "帮我祝他快乐",
        productionNotes: "",
        deliveryNotes: "",
        longitude: '',
        latitude: '',
        deliveryStartTime: "",
        deliveryEndTime: "",
        address1: '',
        address2: '',
        totalPrice: 0,
        startTime: '',
        endTime: '',
        checkOrder: '',
        mainWarehouseId: '',
        customerServiceNotes: '', // 客服备注
        storeInfo: '', // 门店信息
        deliveryRemark: '',// 配送备注
        productRemark: '',// 生产备注
        customerRemark: '',// 客户备注
        orderDetailList: [
          {
            goodsName: "【人气爆款】莓莓红丝绒-三层水果裸蛋糕生日蛋糕7寸",
            skuId: 1320729656057856,
            skuCode: "4.001.0261",
            goodsId: 1320729655402496,
            goodsSpecs: "7寸",
            originalPrice: 19800,
            totalPrice: 19800,
            num: 1,
            remark: "",
            blessings: "生日快乐",
            goodsAttr: "",
            getPrice: ''
          }
        ]
      },
      // 创建订单请求的数据
      listMess: {
        receiverAddress: "西湖区骆家庄西苑一区",
        receiverName: "陈先生",
        receiverPhone: "18868427806",
        channel: 1,
        mainWarehouse: "",
        branchWarehouse: "YB",
        deptId: JSON.parse(window.localStorage.getItem("saber-areaId")).content,
        customerNotes: "帮我祝他快乐",
        productionNotes: "",
        deliveryNotes: "",
        deliveryStartTime: '',
        deliveryEndTime: '',
        longitude: '',
        latitude: '',
        mainWarehouseId: '',
        orderDetailList: [],
        serviceClassList: [],
        partsList: [],
        workOrderProvisionsList: [],
        customizedOrderDetailList: []
      },
      // form表单
      rules: {
        name: [{
          required: true,
          message: "请输入收货人",
          trigger: "change"
        }],
        phone: [
          { required: true, validator: validPhone, trigger: 'change' }
        ],
        totalPrice: [
          { required: true, message: "请输入订单总价", trigger: 'blur' },
          { validator: checkData, trigger: 'change'}
        ],
        channer: [{ required: true, message: "请输入渠道", trigger: "change" }],
        deliveryStartTime: [
          { required: true, message: '请选择日期', trigger: 'change' }
        ],
        startTime: [
          { required: true, message: '请选择时间', trigger: 'change' }
        ],
        endTime: [
          { required: true, message: '请选择时间', trigger: 'change' }
        ],
        city: [
          { required: true,
            message: '请选择仓库',
            trigger: 'change'
          }
        ],
        wareHouse: [
          { required: true, message: "请选择总仓", trigger: "change" }
        ],
        abbr: [{ required: true, message: "请选择分仓", trigger: "change" }],
        address2: [
          {
            required: true,
            validator: validatePass,
            trigger: 'change'
          }
        ],
        channelType: [{ required: true, message: "请选择渠道类别", trigger: "change" }],
        customerServiceNotes: [{ required: false, message: '请输入客服备注', trigger: 'change' }],
        deliveryRemark: [{ required: false, message: '请输入配送备注', trigger: 'change' }],
        storeInfo: [{ required: false, message: '请输入门店信息', trigger: 'change' }],
        productRemark: [{ required: false, message: '请输入生产备注', trigger: 'change' }],
        customerRemark: [{ required: false, message: '请输入客户备注', trigger: 'change' }]
      },
      currentIndex: '', // 地图列表激活
      condition: '', //日期是否为今天
      nowHours: '',
      pickerOptionsStart: {
        disabledDate: time => {
          let yy = new Date().getFullYear();
          let mm = new Date().getMonth() + 1< 10? "0" + (new Date().getMonth() + 1): (new Date().getMonth() + 1);
          let dd = new Date().getDate();
          let nowHours = new Date().getHours() < 10? "0" + new Date().getHours() : new Date().getHours();
          const nowDate = yy + "-" + mm + "-" + dd + ' ';
          this.nowHours = nowHours
          if(nowDate) {
            if(this.listMessage.deliveryStartTime === nowDate) {
              // console.log(parseInt(nowHours) + parseInt(1)+':00')
              this.condition = true
            } else {
              this.condition = false
            }
          }
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      cityLi: { // 城市角色
        roleId: 1
      },
      cityselect: "", // 城市获取列表
      citylist: "", // 下单仓库中的总仓
      abbrlist: "", // 分仓
      shoplist: { // 蛋糕编辑列表
        deptId: JSON.parse(window.localStorage.getItem("saber-areaId")).content,
        page: 1,
        size: 10
      },
      channelTypellist: '', // 渠道类别列表
      channerllist: "", // 渠道列表
      addressFlag: false, // 地址详情列表的显隐
      isaddressFlag: false, // 地址详情列表的显隐
      mapCenter: [121.59996, 31.197646],
      markers: [],
      addressList: '', // 地址详情列表
      pagesize: 5, // 分页
      currentPage: 1, // 分页
      // 总仓
      wareHouse: {
        parentId: JSON.parse(window.localStorage.getItem("saber-areaId")).content
      },
      // 分仓
      abbrHouse: {
        deptId: 1
      },
      getAreaScope: '', // 覆盖物区域
      getWarehouseName: {  // 根据经度纬度，返回分仓总仓名称
        longitude: 1,
        latitude: 2
      },
      getProvisionsGoodsPageQuery: { // 备款商品分页列表(请求)
        goodsName: '',
        page: 1,
        size: 10,
        cityId: JSON.parse(window.localStorage.getItem("saber-areaId")).content, //组织架构ID
      },
      getWarehousesByDeptIds: { // 查询所有仓库信息，划区域
        cityId: JSON.parse(window.localStorage.getItem("saber-areaId")).content,
        deptId: '',
        name: ''
      },
      openEditCakeFlag: false, // 编辑蛋糕列表弹窗
      noEditCakeFlag: true, // 未添加蛋糕时，无蛋糕商品显示
      getGoodsPageList: '', // 备款商品分页列表
      activeName: 'first', // 标签页
      input: "", // 备款蛋糕
      cakeInput: '', // 查询蛋糕
      list: "", // 蛋糕列表
      cakeinglist: {
        num: 1
      },
      tableData: [], // 已选蛋糕列表
      tableCakeData: [],// 点击提交后显示的蛋糕
      shopQuerylist: { // 普通蛋糕请求列表
        deptId: JSON.parse(window.localStorage.getItem("saber-areaId")).content,
      },
      cakelist: '', // 点击添加蛋糕前，将点击的规格的数据传给cakelist
      sumPrice: 0, // 蛋糕总价
      deliveryTimeFlag: false, // 配送时间Flag
      judgeGoodsCloseQuery: { // 判断当前商品是否关闭请求
        warehouseId: '', // 仓库id
        skuCode: '', // sku码
      },
      getSurplusWarehouseLoadQuery: { // 仓库剩余负荷列表
        warehouseId: '',
        // warehouseDeliveryDate: ''
      },
      timelist: [], // 负荷时间点
      warehouseLoadList: [], // 负荷数量
      checkedlist: [],
      idList: [],
      getdeliveryStartTime: '', //开始时间
      getAreaScopeArray: [],
      overlayGroups: [],
      cityId: '',
      getChannelList: { // 渠道列表
        parentId: ''
      },
      shopTotal: 0, // 蛋糕分页
      GoodsPageTotal: 0, // 备款分页
      Loading: true,
      latitudeFlag: false, // 是否改变了城市
      latitude: '',
      longitude: '',
      addressCopyname: '',
      startTime: '',
      endTime: '',
      OrderStartTime: '',
      OrderEndTime: '',
      OrderTimeFlag: false, // 订单标记
      foundOrderFlag: false, // 创建订单按钮点击置灰
      // selectTimeFlag: false, // 时间选择弹框标记
      map: '',//地图
      initialization: 1,// 是否初始化地图
    }
  },
  created(){
    this.deptName=JSON.parse(window.localStorage.getItem("saber-areaname")).content;
    this.listMessage.deptId = JSON.parse(window.localStorage.getItem("saber-areaId")).content;
    // 未点击城市时划区域
    setTimeout(() => {
      this.getArea()
    },500)
  },
  mounted() {
    // this.listMessage.city = JSON.parse(window.localStorage.getItem("saber-areaId")).content
    // console.log(JSON.parse(window.localStorage.getItem("saber-areaId")).content)
    // 城市
    citySelect(this.cityLi).then(res => {
      this.cityselect = res.data.data;
    })
    // 渠道类别列表
    getOrderChannelTypeList().then(res => {
      this.channelTypellist = res.data.data;
    })
    let _this = this;
    // 点击页面空白处
    document.onclick = function(event) {
      var event = event || window.event;
      let targetId = event.target.id;
      let parentId = event.target.parentElement.parentElement.id;
      if(event.target.parentElement.parentElement.parentElement !== null) {
        let parentParentId = event.target.parentElement.parentElement.parentElement.id;
        // 不等于当前点点击的名字
        if((targetId !== 'getDetail') && (targetId !== 'mapDiv') && (parentId !== 'mapDiv') && (parentParentId !== 'mapDiv')) {
          _this.addressFlag = _this.isaddressFlag = false;
        }
      }
    }
  },
  watch: {
    'listMessage.channelType'() {
      if(this.listMessage.channelType == null || this.listMessage.channelType == '')  this.listMessage.channer = this.getChannelList.parentId = '';
    },
    'deptName'() {
      // 未点击城市时划区域
      // this.getArea()
      if(this.initialization > 1) this.map.clearMap();
      this.initialization = 1;
    }
  },
  methods: {
    // 获取城市
    // handleCity(data){
    //   // console.log(data,'data')
    //   // if(data){
    //   //   this.deptName=data.label;
    //   //   this.listMessage.deptId=data.value;
    //   // }else{
    //   //   this.listMessage.deptId=JSON.parse(window.localStorage.getItem("saber-areaId")).content;
    //   //   this.deptName=JSON.parse(window.localStorage.getItem("saber-areaname")).content;
    //   // }

    // },
    // 渠道类型空格过滤
    channelFilter(e) {
      if(e.keyCode == 32) {
        e.returnValue = false;
      }
    },
    getchannelTypeId(e){
      if(e.currentTarget.dataset.id !== ''){
        this.getChannelList.parentId = e.currentTarget.dataset.id
        getOrderChannelList(this.getChannelList).then(res => {
          let result = res.data.data
          result.forEach(item => {
            this.channerllist = result;
            // console.log('this.listMessage.channer',this.listMessage.channer)
            if(this.listMessage.channer !== undefined) {
              if (item.channelKey == this.listMessage.channer) {
                // console.log('有',item)
                this.channerllist = result;
              } else {
                // console.log('没有',item)
                this.channerllist = result;
                this.listMessage.channer = ''
              }
            }
          })
        })
      }
    },
    getchannelList() {
      // console.log('this.getChannelList.parentId',this.getChannelList.parentId);
      // 渠道列表接口
      if(this.getChannelList.parentId !== '') {
        getOrderChannelList(this.getChannelList).then(res => {
          // let result = res.data.data
          this.channerllist = res.data.data;
        })
      } else {
        this.$message.warning('请先选择渠道类别');
        this.channerllist = '';
      }
    },
    // 地图事件
    SearchAddress() {
      if(this.listMessage.address1 !== '') {
        // console.log('1',this.addressList.length)
        let _this = this
        // var map = new AMap.Map('amapDemo')
        var keywords = document.getElementById("getDetail").value;
        AMap.plugin('AMap.Autocomplete', function(){
          // 实例化Autocomplete
          var autoOptions = {
            city: '全国'
          }
          var autoComplete = new AMap.Autocomplete(autoOptions);
          autoComplete.search(keywords, function(status, result) {
            // 搜索成功时，result即是对应的匹配数据
            if(result.tips !== undefined) {
              _this.addressFlag = true;
              _this.addressList = [];
              result.tips.forEach(item => {
                if(item.district.indexOf(_this.deptName) > 1) _this.addressList.push(item);
              })
              result.tips.forEach(otheritem => {
                if(_this.addressList.indexOf(otheritem) == -1) _this.addressList.push(otheritem);
              })
            }
          })
        })
      }
    },
    addMoveMarker() {
      var marker = new AMap.Marker({
        position: new AMap.LngLat(this.getWarehouseName.latitude, this.getWarehouseName.longitude)
      })
      var path = this.getAreaScope
      var polygon = new AMap.Polygon({
        path: path,
        strokeColor: "#000",
        strokeWeight: 6,
        strokeOpacity: 1,
        fillOpacity: 0.4,
        fillColor: '#fff',
        zIndex: 50,
      })
      if(this.getAreaScope !== '') {
        this.map.remove([marker, polygon])
      }
    },
    // 点击地图的列表获取经纬度
    getlnglat(index) {
      if(this.initialization > 1) this.map.clearMap();
      index = (this.currentPage - 1) * this.pagesize + index;
      let _this = this;
      if((typeof index) === 'string') index = 0;
      this.addressFlag = false;
      this.isaddressFlag = false;
      if(this.addressList[index].location !== undefined && this.addressList[index].location.lat !== undefined) {
        this.addressList[index].lat = this.addressList[index].location.lat;
        this.addressList[index].lng = this.addressList[index].location.lng;
      }
      let pois = this.addressList[index];
      this.currentIndex = index;
      if(pois.lat !== undefined) {
        this.addressCopyname = pois.name;
        this.listMess.latitude = pois.lat
        this.listMess.longitude = pois.lng
        this.latitude = pois.lat
        this.longitude = pois.lng
        this.getWarehouseName.latitude = pois.lat
        this.getWarehouseName.longitude = pois.lng
        var path = this.overlayGroups
        // console.log('this.listMessage.address1',pois,this.listMessage.address1)
        var polygon = new AMap.Polygon({
          path: path,
          strokeColor: "#000",
          strokeWeight: 6,
          strokeOpacity: 1,
          fillOpacity: 0.4,
          fillColor: '#fff',
          zIndex: 50,
        })
        if(this.overlayGroups !== '') {
          getWarehouseName(this.getWarehouseName).then(res => {
            // console.log('res',res.data.data)
            if(res.data.msg === '操作成功') {
              this.abbrHouse.deptId = res.data.data.deptId
              if((typeof this.abbrHouse.deptId) === 'number') {
                getSeparateWarehouseList(this.abbrHouse).then(res => {
                  this.abbrlist = res.data.data
                })
              }
              // console.log('在配送区域内',res.data.data)
              this.deptName = res.data.data.cityName;
              this.listMessage.city = res.data.data.cityId;
              this.listMessage.address1 = pois.name;
              this.listMessage.mainWarehouseId = res.data.data.deptId;
              this.wareHouse.parentId = res.data.data.cityId;
              this.listMess.mainWarehouse = res.data.data.deptName;
              this.listMess.mainWarehouseId = res.data.data.deptId;
              this.listMess.warehouseId = res.data.data.id;
              this.listMessage.wareHouse = res.data.data.deptId;
              this.listMessage.abbr = res.data.data.name;
              this.getSurplusWarehouseLoadQuery.warehouseId = res.data.data.id; //当前仓库剩余仓库负荷列表请求仓库id
              this.judgeGoodsCloseQuery.warehouseId = res.data.data.id; // 判断当前商品是否关闭请求仓库id
              // console.log('res.data.data999',res.data.data)
              this.getWarehousesByDeptIds.cityId = res.data.data.cityId;
              this.latitudeFlag = true;
              // console.log('this.addressList[index]888',this.addressFlag,this.isaddressFlag)
              this.getArea();
              // console.log('this.addressList[index]999',this.addressFlag,this.isaddressFlag)
            } else if (res.data.msg == '暂无承载数据') {
              this.$confirm('您选择的地址不在配送范围内, 请到下单仓库中选择城市！', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                // console.log('this.listMess ',this.listMess)
                // this.listMessage.address1 = pois.name;
                // this.deptName = res.data.data.cityName;
                this.latitudeFlag = true;
                this.listMessage.city = this.listMessage.city;
                this.listMessage.address1 = pois.name;
                this.getArea();
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消选择地址'
                })
              })
            }
            // console.log('res.data.data',res.data.data)
          })
        } else {
          this.$confirm('您还未选择城市, 请选则城市！', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$message({
              type: 'success',
              message: '请继续选择城市!'
            });
            this.listMessage.address1 = ''
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消选择城市'
            });
          });
        }
      } else {
        this.$confirm('此地址不存在, 请重新选址！', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '请继续选择地址!'
          });
          // this.listMessage.address1 = ''
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选择地址'
          });
        });
      }
    },
    //方向键（向上）
    selectTopItem () {
      if(this.addressList.length > 0 && this.addressList.length <= 5) {
        if (this.currentIndex >= 0 && this.currentIndex < this.addressList.length - 1) {
          this.currentIndex--;
        } else {
          this.currentIndex = 0;
        }
        // console.log('上',this.currentIndex)
      } else {
        if (this.currentIndex >= 0 && this.currentIndex < this.addressList.length - 1) {
          this.currentIndex--;
        } else {
          this.currentIndex = 0;
        }
      }
    },
    //方向键（向下）
    selectBottomItem (index) {
      if(this.addressList.length > 0 && this.addressList.length <= 5) {
        if (this.currentIndex >= 0 && this.currentIndex < this.addressList.length - 1) {
          this.currentIndex++;
        } else {
          this.currentIndex = 0;
        }
      } else {
        // console.log('2',this.currentIndex >= 0 && this.currentIndex < this.addressList.length - 1)
        if (this.currentIndex >= 0 && this.currentIndex < this.addressList.length - 1) {
          this.currentIndex++;
        } else {
          this.currentIndex = 0;
        }
      }
    },
    // 划区域模块
    getAreaScopeMethod(subCoordinate){
      if(this.map == '') {
        this.map = new AMap.Map("amapDemo", {
          center: [116.400274, 39.905812],
          zoom: 14
        });
      }
      var path = subCoordinate;
      var polygon = new AMap.Polygon({
        path: path,
        strokeColor: "#000",
        strokeWeight: 3,
        strokeOpacity: 1,
        fillOpacity: 0.4,
        fillColor: '#fff',
        zIndex: 50,
      })
      this.markers.forEach((item,index) => {
        // console.log(item[0],item[1])
        if(this.latitudeFlag) {
          var marker = new AMap.Marker({
            position: new AMap.LngLat(item[0], item[1]),
            // size: new AMap.Size(15, 20),
            icon: new AMap.Icon({
              image: `${index == (this.markers.length - 1)? '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png': '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png'}`,
              size: new AMap.Size(28, 36),  //图标所处区域大小
              imageSize: new AMap.Size(28, 36) //图标大小
            }),
            // icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png'
          })
        } else {
          var marker = new AMap.Marker({
            position: new AMap.LngLat(item[0], item[1]),
            // size: new AMap.Size(15, 20),
            icon: new AMap.Icon({
              image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
              size: new AMap.Size(28, 36),  //图标所处区域大小
              imageSize: new AMap.Size(28, 36) //图标大小
            }),
            // icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png'
          })
        }
        // console.log(item)
        marker.setLabel({
          offset: new AMap.Pixel(10, 10),  //设置文本标注偏移量
          content: `<div class='info'>${item[2]}</div>`, //设置文本标注内容
          direction: 'top' //设置文本标注方位
        });
        // map.add(marker)
        this.map.add([marker,polygon]);
      })
      // 缩放地图到合适的视野级别
      if(this.initialization == 1) this.map.setFitView();
      this.initialization += 1;
      // console.log('this.addressList[index]9999',this.listMessage.address1,this.addressFlag,this.isaddressFlag)
      if(this.latitudeFlag) {
        this.map.setZoomAndCenter(50, [this.markers[this.markers.length - 1][0],this.markers[this.markers.length - 1][1]]);
        this.latitudeFlag = false;
        this.addressFlag = this.isaddressFlag = false;
      }
    },
    //  平台单号
    accountInput(val){//账号的实时输入
      //console.log(val);
      let codeReg = new RegExp("[A-Za-z0-9]+"), //正则 英文+数字；
      len=val.length,
      str='';
      for(var i=0;i<len;i++){
        if(codeReg.test(val[i])){
          str+=val[i];
      }
      }
      // console.log(str)
      this.listMessage.platformOrderId=str;
    },
    getwareHouseOpen(val) { // 获取区(即总仓)
      this.listMess.mainWarehouse = val
    },
    // 划过列表颜色改变
    changeColor(index) {
      this.currentIndex = index
      // e.currentTarget.style.background = '#F5F7FA'
    },
    // 离开列表颜色改变
    loseColor(index) {
      this.currentIndex = index
      // e.currentTarget.style.background = '#fff'
    },
    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function (size) {
      this.pagesize = size
    },
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage
    },
    // 未点击城市时划区域
    getArea() {
      // console.log('this.getWarehousesByDeptIds',this.getWarehousesByDeptIds)
      getWarehouseList(this.getWarehousesByDeptIds).then(res => {
        // console.log('划区域',res.data.data)
        this.getAreaScope = res.data.data;
        var isPointInRingList = [];
        var marker = [];
        var overlayGroupsArray = [];
        this.markers = [];
        // this.markers = ''
        let result = res.data.data;
        result.forEach((item,resultindex) => {
          // marker.push(item.longitude,item.latitude)
          // console.log(item.name)
          marker.push([item.longitude,item.latitude,`${item.name}`])
        // console.log(res[index].geoJson.geometry.coordinates,'res[index].geoJson.geometry.coordinates[0]')
          if(result[resultindex].geoJson.geometry !== '') {
            overlayGroupsArray.push(result[resultindex].geoJson.geometry.coordinates[0])
            // console.log('result[resultindex].geoJson.geometry.coordinates[0]',result[resultindex].geoJson.geometry.coordinates[0])
            result[resultindex].geoJson.geometry.coordinates[0].forEach((item) => {
              // console.log('item99999999',item)
              isPointInRingList.push(item)
            })
          }
        })
        if(this.latitude !== '' && this.latitude !== ''&& this.addressCopyname !== '' && this.latitudeFlag) {
          marker.push([this.longitude,this.latitude,this.addressCopyname]);
        }
        this.markers = marker;
        // console.log('isPointInRingList','this.markers',overlayGroupsArray);
        this.getAreaScopeArray = isPointInRingList;
        this.overlayGroups = overlayGroupsArray;
        this.getAreaScopeMethod(this.overlayGroups);
      })
      // 总仓
      if (typeof this.wareHouse.parentId === "number") {
        getMainWarehouseList(this.wareHouse).then(res => {
          this.citylist = res.data.data;
        })
      }
    },
    // 下单仓库城市获取
    cityclick(listMessage) {
      // console.log('888889')
      if(listMessage){
        // console.log(listMessage)
        this.deptName=listMessage.label;
        this.listMessage.city=listMessage.value;
        this.wareHouse.parentId = listMessage.value;
        this.getWarehousesByDeptIds.cityId = listMessage.value;
      }else{
        this.listMessage.city=JSON.parse(window.localStorage.getItem("saber-areaId")).content;
        this.deptName=JSON.parse(window.localStorage.getItem("saber-areaname")).content;
      }
      getWarehouseList(this.getWarehousesByDeptIds).then(res => {
        this.getAreaScope = res.data.data;
        var isPointInRingList = [];
        var marker = [];
        var overlayGroupsArray = [];
        this.markers = [];
        // this.markers = ''
        let result = res.data.data;
        result.forEach((item,resultindex) => {
          // marker.push(item.longitude,item.latitude)
          // console.log(item.name)
          marker.push([item.longitude,item.latitude,`${item.name}`])
        // console.log(res[index].geoJson.geometry.coordinates,'res[index].geoJson.geometry.coordinates[0]')
          if(result[resultindex].geoJson.geometry !== '') {
            overlayGroupsArray.push(result[resultindex].geoJson.geometry.coordinates[0])
            result[resultindex].geoJson.geometry.coordinates[0].forEach((item) => {
              // console.log('item',item)
              isPointInRingList.push(item);
            })
          }
        })
        this.markers = marker;
        // console.log('isPointInRingList','this.markers',this.markers)
        this.getAreaScopeArray = isPointInRingList;
        this.overlayGroups = overlayGroupsArray;
        // console.log('var markers = [];',this.getAreaScopeArray);
        this.getAreaScopeMethod(this.overlayGroups);
      })
      // 总仓
      if(listMessage){
        // 渠道列表接口
        getMainWarehouseList(this.wareHouse).then(res => {
          let result = res.data.data
          if(result.length > 0) {
            result.forEach(item => {
              this.citylist = result;
              // console.log('this.listMessage.channer',this.listMessage.channer)
              if(this.listMessage.wareHouse !== undefined) {
                if (item.id == this.listMessage.wareHouse) {
                  // console.log('有',item)
                  this.citylist = result;
                } else {
                  // console.log('没有',item)
                  this.citylist = result;
                  this.listMessage.wareHouse = '';
                  this.listMessage.abbr = '';
                  this.abbrlist = [];
                }
              }
            })
          } else {
            this.citylist = result;
            this.listMessage.wareHouse = '';
            this.listMessage.abbr = '';
            this.abbrlist = [];
          }
        })
      }
    },
    // 下单分仓获取
    wareclick(data) {
      this.listMessage.mainWarehouseId = data;
      this.listMess.mainWarehouseId = data;
      this.abbrHouse.deptId = data;
      if(data){
        // 分仓列表接口
        getSeparateWarehouseList(this.abbrHouse).then(res => {
          let result = res.data.data
          // console.log('res.data.data',res.data.data)
          if(result.length > 0) {
            result.forEach(item => {
              this.abbrlist = result;
              // console.log('this.listMessage.channer',this.listMessage.channer)
              if(this.listMessage.abbr !== undefined) {
                if (item.id == this.listMessage.abbr) {
                  // console.log('有',item)
                  this.abbrlist = result;
                } else {
                  // console.log('没有',item)
                  this.abbrlist = result;
                  this.listMessage.abbr = '';
                }
              }
            })
          } else {
            this.abbrlist = result;
            // this.listMessage.abbr = '';
          }
        })
      }
    },
    // 标签页
    handleClick(tab) {
      // console.log(' tab',tab.label);
      if(tab.label == '商品') {
        this.getCakeList(); // 普通蛋糕分页列表
      } else if (tab.label == '备款蛋糕') {
        this.getProvisionsGoodsPageList();  // 备款商品分页列表
      }
    },
    // 普通蛋糕查询
    open() {
      // console.log('this.listMessage.city',this.listMessage.city)
      this.Loading = true;
      this.shoplist.deptId = this.listMessage.city
      this.shoplist.name = this.cakeInput;
      shopList(this.shoplist).then(res => {
        this.shopTotal = res.data.data.total;
        this.list = res.data.data.rows;
      });
      setTimeout(() => {
        this.Loading = false;
      }, 0.5 * 1000);
    },
    getBlessing(val) { // 蛋糕表格祝福语
      // console.log(val)
    },
    // 蛋糕规格（型号）选择
    choiceCheck(cakeing,index) {
      this.cakelist = cakeing;
    },
    // 添加蛋糕
    addEditCake(item) {
      let goodsSkuVOS = [];
      this.tableData.forEach(cakeitem => {
        // console.log(cakeitem.id,'cake.id')
        goodsSkuVOS.push(cakeitem.id)
      })
      // console.log(this.judgeGoodsCloseQuery.warehouseId !== '',this.judgeGoodsCloseQuery.warehouseId !== undefined)
      if(this.judgeGoodsCloseQuery.warehouseId !== '' && this.judgeGoodsCloseQuery.warehouseId !== undefined) {
        if(this.cakelist) {
          // console.log('，请选择仓库后再添加蛋糕',this.cakelistm,this.cakelist.length)
          if(goodsSkuVOS.indexOf(this.cakelist.id) == -1) {
            if(item.id == this.cakelist.goodsId) {
              this.cakelist.goodsSpecs = this.cakelist.specs; // 尺寸
              this.cakelist.goodsName = this.cakelist.goodsName; // 蛋糕名称
              this.cakelist.skuId = this.cakelist.id;
              this.cakelist.skuCode = this.cakelist.skuCode;
              this.cakelist.goodsId = this.cakelist.goodsId;
              this.cakelist.getPrice = this.cakelist.price;
              this.cakelist.originalPrice = this.cakelist.getPrice;
              this.cakelist.totalPrice = this.cakelist.getPrice;
              this.cakelist.ProvisionsFlag = 1;
              this.cakelist.reserveCakeFlag = true;
              this.cakelist.num = 1;
              this.judgeGoodsCloseQuery.skuCode = this.cakelist.skuCode;
              judgeGoodsClose(this.judgeGoodsCloseQuery).then(res => {
                if(res.data.code == 200) {
                  if(res.data.data == true) {
                    this.$message({
                      showClose: true,
                      message: '添加商品失败，所选仓库没有生产该蛋糕的原料。',
                      type: 'error'
                    });
                  } else if (res.data.data == false) {
                    this.$message({
                      showClose: true,
                      message: '添加商品成功',
                      type: 'success'
                    });
                    if (this.listMess.orderDetailList.length === 0 && this.tableData.length === 0 && this.listMess.customizedOrderDetailList.length === 0 && this.listMess.serviceClassList.length === 0 && this.listMess.partsList.length === 0) {
                      if(this.cakelist.categoryName === '蛋糕') {
                        this.listMess.orderDetailList[0] = this.cakelist;
                      } else if (this.cakelist.categoryName === '定制蛋糕') {
                        this.listMess.customizedOrderDetailList[0] = this.cakelist;
                      } else if (this.cakelist.categoryName === '服务费') {
                        this.listMess.serviceClassList[0] = this.cakelist;
                      } else if (this.cakelist.categoryName === '配件') {
                        this.listMess.partsList[0] = this.cakelist;
                      }
                      this.tableData[0] = this.cakelist;
                    } else {
                      if(this.cakelist.categoryName === '蛋糕') {
                        this.listMess.orderDetailList.push(this.cakelist);
                      } else if (this.cakelist.categoryName === '定制蛋糕') {
                        this.listMess.customizedOrderDetailList.push(this.cakelist);
                      } else if (this.cakelist.categoryName === '服务费') {
                        this.listMess.serviceClassList.push(this.cakelist);
                      } else if (this.cakelist.categoryName === '配件') {
                        this.listMess.partsList.push(this.cakelist);
                      }
                      this.tableData.push(this.cakelist)
                    }
                    this.showPrice()
                  }
                  this.cakelist = ''
                }
                // console.log('this.tableData蛋糕',this.tableData)
              })
            } else {
              console.log(this.cakelist,'this.cakelist',item.id)
              this.$message({
                message: '您选择的规格的所属商品与此商品不一致，请重新选择规格后再添加商品',
                type: 'warning'
              });
            }
          } else {
            this.$message({
              message: '此商品已经添加过，请不要重复添加',
              type: 'warning'
            });
          }
        } else {
          this.$message({
            message: '您还未选择规格，请选择规格后再添加商品',
            type: 'warning'
          });
        }
      } else {
        // console.log('您还未选择仓库，请选择仓库后再添加蛋糕',this.cakelist)
        this.$message({
          message: '您还未选择仓库，请选择仓库后再添加商品',
          type: 'warning'
        });
      }
    },
    // 备款蛋糕规格（型号）选择
    choiceGoodsCheck(cakeMessage) {
      let goodsSkuVOS = [];
      this.tableData.forEach(cakeitem => {
        goodsSkuVOS.push(cakeitem.id)
      })
      if(this.judgeGoodsCloseQuery.warehouseId !== '' && this.judgeGoodsCloseQuery.warehouseId !== undefined) {
        if(goodsSkuVOS.indexOf(cakeMessage.id) == -1) {
          cakeMessage.specs = cakeMessage.goodsSpecs; // 尺寸
          cakeMessage.goodsName = cakeMessage.goodsName; // 蛋糕名称
          cakeMessage.skuId = cakeMessage.id;
          cakeMessage.skuCode = cakeMessage.skuCode;
          cakeMessage.goodsId = cakeMessage.goodsId;
          cakeMessage.price = cakeMessage.cakePrice;
          cakeMessage.getPrice = cakeMessage.cakePrice;
          cakeMessage.num = cakeMessage.cakeNum;
          cakeMessage.ProvisionsFlag = 2;
          cakeMessage.reserveCakeFlag = false;
          this.judgeGoodsCloseQuery.skuCode = cakeMessage.skuCode;
          judgeGoodsClose(this.judgeGoodsCloseQuery).then(res => {
            if(res.data.code == 200) {
              if(res.data.data == true) {
                this.$message({
                  showClose: true,
                  message: '添加蛋糕失败，所选仓库没有生产该蛋糕的原料。',
                  type: 'error'
                });
              } else if (res.data.data == false) {
                this.$message({
                  showClose: true,
                  message: '添加蛋糕成功',
                  type: 'success'
                });
                if (this.listMess.workOrderProvisionsList.length === 0 && this.tableData.length == 0) {
                  this.listMess.workOrderProvisionsList[0] = cakeMessage;
                  this.tableData[0] = cakeMessage;
                } else {
                  this.tableData.push(cakeMessage);
                  this.listMess.workOrderProvisionsList.push(cakeMessage);
                }
                this.showPrice()
              }
            }
          })
        } else {
          this.$message({
            message: '此蛋糕已经添加过，请不要重复添加',
            type: 'warning'
          });
        }
      } else {
        this.$message({
          message: '您还未选择仓库，请选择仓库后再添加蛋糕',
          type: 'warning'
        });
      }
    },
    onAddSumbit() {
      this.openEditCakeFlag = false;
      if(this.tableData.length == 0) {
        this.noEditCakeFlag = true;
        this.listMess.workOrderProvisionsList = [];
        this.listMess.orderDetailList = [];
        this.listMess.partsList = [];
        this.listMess.serviceClassList = [];
        this.listMessage.totalPrice = 0;
      } else {
        this.noEditCakeFlag = false;
        this.tableCakeData = this.tableData;
        this.sumPrice = JSON.stringify(this.sumPrice);
        this.sumPrice = JSON.parse(this.sumPrice);
        this.listMessage.totalPrice = (this.sumPrice/100).toFixed(2);
      }
    },
    openEditCake() { // 打开蛋糕弹窗
      this.activeName = 'first'; // 编辑蛋糕打开即“商品”
      this.getCakeList(); // 普通蛋糕分页列表
    },
    handleCakeClose() { // 关闭蛋糕弹窗
      this.$confirm('确认关闭？')
        .then(() => {
          this.tableData = [];
          this.tableCakeData = [];
          this.listMess.workOrderProvisionsList = [];
          this.listMess.orderDetailList = [];
          this.listMess.partsList = [];
          this.listMess.serviceClassList = [];
          this.openEditCakeFlag = false;
          this.noEditCakeFlag = false;
          this.sumPrice = 0;
          this.listMessage.totalPrice = this.sumPrice;
        })
        .catch(() => {});
    },
    showPrice() { // 计算蛋糕价格
      this.sumPrice = 0
      this.tableData.forEach((value,index) => {
        if(this.tableData.length === 1 ) {
          this.sumPrice = value.getPrice
          this.listMessage.totalPrice = this.sumPrice;
        } else if(this.tableData.length > 1) {
          this.sumPrice += value.getPrice
          this.listMessage.totalPrice = this.sumPrice;
        }
      })
    },
    // 商品添加减少
    handleEdit(index,e) {
      this.tableData[index].num ++
      e.currentTarget.nextElementSibling.innerHTML = this.tableData[index].num
      this.tableData[index].getPrice = this.tableData[index].num * this.tableData[index].price
      e.currentTarget.parentElement.parentElement.nextElementSibling.lastElementChild.firstElementChild.firstElementChild.innerHTML = (this.tableData[index].num * this.tableData[index].price/100).toFixed(2)
      this.showPrice()
    },
    handleDelete(index,e) {
      if(this.tableData[index].num > 1) {
        this.tableData[index].num --
        e.currentTarget.previousElementSibling.innerHTML = this.tableData[index].num
        this.tableData[index].getPrice = this.tableData[index].num * this.tableData[index].price
        e.currentTarget.parentElement.parentElement.nextElementSibling.lastElementChild.firstElementChild.firstElementChild.innerHTML = (this.tableData[index].num * this.tableData[index].price/100).toFixed(2)
        this.showPrice()
      }
    },
    // 删除单个订单
    cleanOrder(index,e) {
      let ProvisionsFlag = this.tableData[index].ProvisionsFlag;
      // console.log(this.tableData[index].ProvisionsFlag,'this.tableData[index].ProvisionsFlag',e.currentTarget.dataset.id);
      this.$delete(this.tableData,index);
      if(ProvisionsFlag == 1) {
        // console.log('ProvisionsFlag',ProvisionsFlag,e.currentTarget.dataset.id)
        this.listMess.orderDetailList.forEach((item,ordindex) => {
          if(item.id == e.currentTarget.dataset.id) this.$delete(this.listMess.orderDetailList,ordindex)
        })
        // console.log(this.listMess.orderDetailList)
      } else if (ProvisionsFlag == 2) {
        this.listMess.workOrderProvisionsList.forEach((item,ordindex) => {
          if(item.id == e.currentTarget.dataset.id) this.$delete(this.listMess.orderDetailList,ordindex)
        })
      }
      this.showPrice();
    },
    // 普通蛋糕分页列表
    getCakeList() {
      this.Loading = true;
      if(this.listMessage.city !== undefined && this.listMessage.city !== '') {
        this.openEditCakeFlag = true;
        this.shoplist.deptId = this.listMessage.city;
        shopList(this.shoplist).then(res => {
          this.shopTotal = res.data.data.total;
          this.list = res.data.data.rows;
        })
        setTimeout(() => {
          this.Loading = false;
        }, 1 * 1000);
      } else {
        this.$confirm('您还未选择下单仓库，请先选择下单仓库', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '请继续选择下单仓库!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消选择'
          });
        });
      }
    },
    // 备款商品分页列表
    getProvisionsGoodsPageList() {
      this.Loading = true;
      this.getProvisionsGoodsPageQuery.cityId = this.listMessage.city;
      getProvisionsGoodsPage(this.getProvisionsGoodsPageQuery).then(res => {
        this.GoodsPageTotal = res.data.data.total;
        this.getGoodsPageList = res.data.data.rows;
        // console.log(res.data.data,'res.data.data')
      })
      setTimeout(() => {
        this.Loading = false;
      }, 0.5 * 1000);
    },
    //备款商品分页列表(查询)
    ProvisionsGoodsPageopen() {
      this.Loading = true;
      if(this.getGoodsPageList !== '') {
        this.getProvisionsGoodsPageQuery.cityId = this.listMessage.city;
        this.getProvisionsGoodsPageQuery.goodsName = this.input;
        getProvisionsGoodsPage(this.getProvisionsGoodsPageQuery).then(res => {
          this.GoodsPageTotal = res.data.data.total;
          this.getGoodsPageList = res.data.data.rows;
          // console.log(res.data.data,'res.data.data查到了')
        })
        setTimeout(() => {
          this.Loading = false;
        }, 0.5 * 1000);
      }
    },
    //  取消订单
    // cancelOrder () {
    //   this.listMess.orderDetailList.length = 0
    //   this.tableData = ''
    //   this.sumPrice = 0
    //   // this.blankFlag = true
    //   // this.tableFlag = false
    // },
    // 创建订单并获取后台单号
    onSubclick(formName) {
      this.foundOrderFlag = true;
      this.listMess.deliveryStartTime = this.listMessage.deliveryStartTime;
      if(this.listMess.deliveryStartTime !== '' && this.$refs.getdeliveryTime !== undefined && this.$refs.getdeliveryTime.deliveryEndTime !== '') {
        this.listMess.deliveryStartTime = this.listMessage.deliveryStartTime+this.$refs.getdeliveryTime.deliveryStartTime
        this.listMess.deliveryEndTime = this.listMessage.deliveryStartTime+this.$refs.getdeliveryTime.deliveryEndTime
        // console.log('有',this.listMess.deliveryStartTime)
        // this.listMess.warehouseLoadId = this.$refs.getdeliveryTime.warehouseLoadId
        // this.listMess.receiverAddress = this.listMessage.address1 + this.listMessage.address2
        this.listMess.receiverAddress = this.listMessage.address2
        this.listMess.receiverName = this.listMessage.name
        this.listMess.receiverPhone = this.listMessage.phone
        this.listMess.platformOrderId = this.listMessage.platformOrderId
        this.listMess.channelType = this.listMessage.channelType // 渠道类别
        this.listMess.channel = this.listMessage.channer // 渠道
        this.listMess.branchWarehouse = this.listMessage.abbr // 分仓
        this.listMess.deptId = this.listMessage.city // 城市
        // console.log('this.listMess.platformOrderId',this.listMess.platformOrderId)
        this.listMess.customerNotes = this.listMessage.customerRemark // 顾客备注
        this.listMess.productionNotes = this.listMessage.productRemark // 生产备注
        this.listMess.deliveryNotes = this.listMessage.deliveryRemark
        this.listMess.customerServiceNotes = this.listMessage.customerServiceNotes
        this.listMess.storeInfo = this.listMessage.storeInfo;
        this.listMess.totalPrice = this.listMessage.totalPrice * 100;
        this.$refs[formName].validate((valid) => {
          // console.log('this.listMess09',this.listMess)
          if (valid) {
            if(this.listMess.latitude !== '' && this.listMess.longitude !== '') {
              if((this.listMess.workOrderProvisionsList.length > 0) && ((this.listMess.customizedOrderDetailList.length == 0) || (this.listMess.orderDetailList.length == 0) || (this.listMess.serviceClassList.length == 0) || (this.listMess.partsList.length == 0))) {
                // this.uniCode(); // 特殊字符编码
                createOrder(this.listMess).then(res => {
                  if(res.data.code == 200) {
                    this.orderNumber = res.data.data.data
                    createOrderByProvisions({ 'workOrderProvisionsList': this.listMess.workOrderProvisionsList }).then(res => {
                      // console.log(res.data.data,'data.data')
                      if (res.data.code == 200) {
                        this.$alert(`下单成功！后台单号：${this.orderNumber}`, '提示', {
                          confirmButtonText: '确定',
                          callback: action => {
                            this.$message({
                              type: 'success',
                              message: `操作成功`
                            });
                            this.$refs[formName].resetFields() //
                            this.delCreateOrder();
                          }
                        })
                      }
                      this.$refs[formName].resetFields()
                      this.delCreateOrder();
                    })
                  } else if (res.data.code == 300) {
                    this.$message({
                      type: 'warning',
                      message: `${res.data.msg}`
                    })
                  } else if (res.data.code == 301) {
                    this.$message({
                      type: 'warning',
                      message: `${res.data.msg}`
                    })
                  }
                  this.$refs[formName].resetFields() //
                  this.delCreateOrder();
                }).catch(error => {
                  this.$refs[formName].resetFields()
                  this.delCreateOrder();
                })
              } else if (((this.listMess.customizedOrderDetailList.length > 0) || (this.listMess.orderDetailList.length > 0) || (this.listMess.partsList.length > 0) || (this.listMess.serviceClassList.length > 0)) && this.listMess.workOrderProvisionsList.length == 0) {
                // this.uniCode(); // 特殊字符编码
                createOrder(this.listMess).then(res => {
                  if(res.data.code == 200) {
                    this.orderNumber = res.data.data.data
                    this.$alert(`下单成功！后台单号：${this.orderNumber}`, '提示', {
                      confirmButtonText: '确定',
                      callback: action => {
                        this.$message({
                          type: 'success',
                          message: `操作成功`
                        });
                        this.$refs[formName].resetFields()
                        this.delCreateOrder();
                      }
                    })
                  } else if (res.data.code == 300) {
                    this.$message({
                      type: 'warning',
                      message: `${res.data.msg}`
                    })
                  } else if (res.data.code == 301) {
                    this.$message({
                      type: 'warning',
                      message: `${res.data.msg}`
                    })
                  }
                  this.$refs[formName].resetFields()
                  this.delCreateOrder();
                }).catch(error => {
                  console.log('error',error)
                  this.$refs[formName].resetFields()
                  this.delCreateOrder();
                })
              } else if ((this.listMess.workOrderProvisionsList.length > 0) && ((this.listMess.orderDetailList.length > 0) || (this.listMess.serviceClassList.length > 0) || (this.listMess.partsList.length > 0) || (this.listMess.customizedOrderDetailList.length > 0))) {
                // this.uniCode(); // 特殊字符编码
                // console.log(this.listMess.orderDetailList.length,this.listMess.workOrderProvisionsList.length)
                createOrder(this.listMess).then(res => {
                  if(res.data.code == 200) {
                    this.orderNumber = res.data.data.data
                    createOrderByProvisions({ 'workOrderProvisionsList': this.listMess.workOrderProvisionsList }).then(res => {
                      // console.log(res.data.data,'data.data')
                      if (res.data.code == 200) {
                        this.$alert(`下单成功！后台单号：${this.orderNumber}`, '提示', {
                          confirmButtonText: '确定',
                          callback: action => {
                            this.$message({
                              type: 'success',
                              message: `操作成功`
                            });
                            this.$refs[formName].resetFields()
                            this.delCreateOrder();
                          }
                        })
                      }
                    })
                  } else if (res.data.code == 300) {
                    this.$message({
                      type: 'warning',
                      message: `${res.data.msg}`
                    })
                  } else if (res.data.code == 301) {
                    this.$message({
                      type: 'warning',
                      message: `${res.data.msg}`
                    })
                  }
                  this.$refs[formName].resetFields()
                  this.delCreateOrder();
                }).catch(error => {
                  console.log('error',error)
                  this.$refs[formName].resetFields()
                  this.delCreateOrder();
                })
              } else if ((this.listMess.workOrderProvisionsList.length == 0) && (this.listMess.orderDetailList.length == 0) && (this.listMess.customizedOrderDetailList.length == 0) && (this.listMess.partsList.length == 0) && (this.listMess.serviceClassList.length == 0)) {
                console.log('4')
                this.$confirm('你还未添加商品，请添加商品?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                  this.$message({
                    type: 'success',
                    message: '请继续添加商品!'
                  });
                  this.foundOrderFlag = false;
                  // this.$refs[formName].resetFields()
                }).catch(() => {
                  this.$message({
                    type: 'info',
                    message: '已取消添加商品'
                  });
                  this.foundOrderFlag = false;
                })
              }
            } else {
              this.$message.warning('定位获取失败，请再次尝试!');
              this.foundOrderFlag = false;
            }
          } else {
            this.$confirm('还有信息未填完整，请补充完整?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.$message({
                type: 'success',
                message: '请完善信息!'
              });
              this.foundOrderFlag = false;
              // this.$refs[formName].resetFields()
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消创建订单'
              });
              this.$refs[formName].resetFields();
              this.listMess.latitude = '';
              this.listMess.longitude = '';
              this.listMessage.thirdOrder = '';
              this.listMessage.address1 = '';
              this.listMessage.address2 = '';
              this.$refs.getdeliveryTime.deliveryEndTime = '';
              this.$refs.getdeliveryTime.deliveryStartTime = '';
              this.$refs.getdeliveryTime.StartTime = '';
              this.$refs.getdeliveryTime.EndTime = '';
              this.$refs.getdeliveryTime.checkedIndex = '';
              this.judgeGoodsCloseQuery.warehouseId = '';
              this.foundOrderFlag = false;
              // this.blankFlag = true
              // this.tableFlag = false
            });
            return false;
          }
        })
      } else {
        this.$alert(`您还未选配送时间，请选择配送时间`, '提示', {
          confirmButtonText: '确定',
          callback: action => {
            this.$message({
              type: 'success',
              message: `请继续选择配送时间`
            });
            this.foundOrderFlag = false;
          }
        })
      }
    },
    // 编码
    uniCode() {
      this.listMess.deliveryNotes = escape(this.listMess.deliveryNotes); // 配送备注
      this.listMess.customerServiceNotes = escape(this.listMess.customerServiceNotes); // 客服备注
      this.listMess.productionNotes = escape(this.listMess.productionNotes); // 生产备注
      this.listMess.customerNotes = escape(this.listMess.customerNotes); // 客户备注
      this.listMess.storeInfo = escape(this.listMess.storeInfo); // 门店信息
    },
    // 创建订单后（清空表单）
    delCreateOrder() {
      this.noEditCakeFlag = true
      this.listMessage.thirdOrder = ''
      this.listMessage.address1 = ''
      this.sumPrice = 0;
      this.listMessage.totalPrice = this.sumPrice;
      this.listMess.orderDetailList = [];
      this.listMess.workOrderProvisionsList = [];
      this.listMess.partsList = [];
      this.listMess.serviceClassList = [];
      this.tableData = [] //
      this.listMessage.address2 = '' //
      this.listMess.deliveryStartTime = ''
      this.listMess.latitude = '';
      this.listMess.longitude = '';
      // console.log('this.listMess.deliveryStartTime',this.listMess.deliveryStartTime)
      this.$refs.getdeliveryTime.deliveryEndTime = '';
      this.$refs.getdeliveryTime.deliveryStartTime = '';
      this.$refs.getdeliveryTime.StartTime = '';
      this.$refs.getdeliveryTime.EndTime = '';
      this.$refs.getdeliveryTime.checkedIndex = '';
      this.listMessage.platformOrderId = '';
      this.addMoveMarker();
      this.judgeGoodsCloseQuery.warehouseId = '';
      this.foundOrderFlag = false;
    },
    deliveryTimeOpen() {
      this.orderStartEndTime = 'foundOrder'
      if(this.listMessage.abbr !== undefined && this.listMessage.abbr !== '') {
        this.getgetSurplusWarehouseLoadList();
        this.deliveryTimeFlag = true;
      } else {
        this.$message({
          message: '请选择仓库',
          type: 'warning'
        });
      }
    },
    cancelSelectTime() { // 取消选择配送时间
      this.deliveryTimeFlag = false;
      this.$refs.getdeliveryTime.deliveryEndTime = '';
      this.$refs.getdeliveryTime.deliveryStartTime = '';
      this.$refs.getdeliveryTime.checkedIndex = '';
    },
    // 配送时间关闭弹窗
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(() => {
          done();
          this.deliveryTimeFlag = false;
          this.$refs.getdeliveryTime.deliveryEndTime = '';
          this.$refs.getdeliveryTime.deliveryStartTime = '';
          this.$refs.getdeliveryTime.checkedIndex = '';
        })
        .catch(() => {});
    },
    selectSubmit() {
      if(this.$refs.getdeliveryTime.deliveryEndTime == '' || this.$refs.getdeliveryTime.ischecked.indexOf(true) == -1) {
        this.$message({
          message: '配送时间不能为空',
          type: 'warning'
        });
      } else {
        this.listMess.deliveryStartTime = this.$refs.getdeliveryTime.getdeliveryStartTime+this.$refs.getdeliveryTime.deliveryStartTime
        this.listMess.deliveryEndTime = this.$refs.getdeliveryTime.getdeliveryStartTime+this.$refs.getdeliveryTime.deliveryEndTime
        this.deliveryTimeFlag = false;
      }
    },
    // 获取分仓id
    getwarehouseId(val) {
      // console.log(val,'获取分仓')
      getSeparateWarehouseList(this.abbrHouse).then(res => {
        this.abbrlist = res.data.data
      })
      if(val) {
        this.listMessage.abbr = val.label;
        this.listMessage.warehouseId = val.value;
        this.listMess.branchWarehouse = val.label; // 分仓
        this.listMess.warehouseId = val.value;
        this.getSurplusWarehouseLoadQuery.warehouseId = val.value;
        this.judgeGoodsCloseQuery.warehouseId = val.value; // 判断当前商品是否关闭请求仓库id
      }
      // console.log('this.listMess.branchWarehouse',this.listMess.branchWarehouse)
    },
    // 获取分仓name
    // getwarehouseName(val) {
    //   console.log(val,'获取分仓name')
    //   if(val) {
    //     this.listMessage.abbr = val;
    //   }
    // },
    // // 获取分仓id
    // getwarehouseId(val) {
    //   console.log(val,'获取分仓id')
    //   if(val) {
    //     // this.listMessage.abbr = val.label;
    //     this.listMess.warehouseId = val
    //     this.listMessage.warehouseId = val
    //     this.getSurplusWarehouseLoadQuery.warehouseId = val
    //     this.judgeGoodsCloseQuery.warehouseId = val // 判断当前商品是否关闭请求仓库id
    //   }
    // },
    getgetSurplusWarehouseLoadList() {
      this.Loading = true;
      getSurplusWarehouseLoadList(this.getSurplusWarehouseLoadQuery).then(res => {
        this.timelist = res.data.data.warehouseLoadAddSonRequestList[0].timeSlotList
        this.warehouseLoadList = res.data.data.warehouseLoadAddSonRequestList[0].warehouseLoadList
        this.idList = res.data.data.warehouseLoadAddSonRequestList[0].idList
        if(this.timelist.length > 0 && this.warehouseLoadList.length > 0 && this.idList.length > 0) {
          this.Loading = false;
          this.$refs.getdeliveryTime.disableChecked = false;
          this.checkedlist = []
          let checklist = { }
          res.data.data.warehouseLoadAddSonRequestList[0].warehouseLoadList.forEach((item,index) => {
            checklist = { 'num' : res.data.data.warehouseLoadAddSonRequestList[0].warehouseLoadList[index] }
            this.checkedlist.push(checklist)
          })
          this.checkedlist.forEach(item => {
            this.$set(item, "checked", false)
          })
          if(this.$refs.getdeliveryTime.checkedIndex) {
            if(this.$refs.getdeliveryTime.lastCheckedFlag) {
              // console.log('000')
              this.checkedlist[this.$refs.getdeliveryTime.checkedIndex].checked = false;
              this.$refs.getdeliveryTime.disableChecked = false;
              // console.log('item',this.$refs.getdeliveryTime.ischecked,this.$refs.getdeliveryTime.checkedlist)
            } else {
              // console.log(this.$refs.getdeliveryTime.lastdeliveryStartTime,this.$refs.getdeliveryTime.getdeliveryStartTime)
              this.checkedlist[this.$refs.getdeliveryTime.checkedIndex].checked = true;
              this.$refs.getdeliveryTime.disableChecked = true;
            }
          }
          this.timelist.forEach((item,index) => {
            let yy = new Date().getFullYear();
            let mm = new Date().getMonth() + 1< 10? "0" + (new Date().getMonth() + 1): (new Date().getMonth() + 1);
            let dd = new Date().getDate() < 10? "0" + new Date().getDate(): new Date().getDate();
            let nowDate = yy + "-" + mm + "-" + dd + ' ';
            let nowHours = new Date().getHours() < 10? "0" + new Date().getHours() : new Date().getHours();
            let deliveryTime = parseInt(this.timelist[index].slice(9,11))// 配送时间（小时）
            // console.log('nowHours',parseInt(nowHours) + 1,'deliveryTime',deliveryTime)
            // console.log('this.$ref',this.$refs.getdeliveryTime.getdeliveryStartTime,this.$refs.getdeliveryTime.getdeliveryStartTime == nowDate)
            if(this.$refs.getdeliveryTime.getdeliveryStartTime == nowDate && Number(deliveryTime) <= ( parseInt(nowHours) + 1 ) ) {
              if(deliveryTime == 0) {
                this.checkedlist[index].getHour = false;
                this.timelist[index] = '23:00:00-24:00:00'
              } else {
                this.checkedlist[index].getHour = true;
              }
              // console.log('今天',this.checkedlist)
            } else {
              this.checkedlist[index].getHour = false;
              if(deliveryTime == 0) {
                this.timelist[index] = '23:00:00-24:00:00';
              }
            }
          })
        } else {
          this.$message.warning("该仓库设置存在问题，请更换仓库或联系快乐部主管补全仓库信息");
        }
        // console.log('this.checkedlist',this.checkedlist)
      })
    },
  }
};
</script>
<style type="text/css">
  #panel {
    position: absolute;
    background-color: white;
    max-height: 260px;
    overflow-y: auto;
    top: 8px;
    right: 10px;
    width: 280px;
    opacity: .9;
  }
</style>
<style lang="scss">
.page-component__scroll .el-scrollbar__wrap {
  overflow-x: hidden;
}
.app-found {
  min-height: calc(100vh - 50px);
  overflow: hidden;
}
.amap {
  height: 600px;
  margin: 0 10px 10px 10px;
}
.else-message {
  margin: 0 0 15px 37px;
  font-size: 20px;
  font-weight: 600;
}
.line {
  color: #C0C4CC;
  font-weight: 600;
}
/****      地图搜索下拉地址   */
.getadressDetailDiv .adressDetailDiv {
  width: 600px;
  background: #fff;
  position: absolute;
  top: 35px;
  left: 118.68px;
  z-index: 99;
}
.adressDetail {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid #DCDFE6;
  // width: 300px;
}
.adressDetail li {
  border-bottom: 1px solid #DCDFE6;
  // background: #fff;
}
.adressDetail li p{
  margin: 0;
  padding: 0 10px;
  list-style: none;
  width: 280px;
  text-align: left;
  line-height: 1.6;
}
// .adressDetail li.hover {
//   background-color: #F5F7FA;
// }
.adressDetail li p:first-child {
  font-size: 17px;
}
.adressDetail li p:last-child {
  color: #999;
}
.addressActive {
  // background-color: #000;
  background: #F5F7FA;
}
.EditCakeLi {
  padding: 15px;
  width: 80%;
  list-style: none;
  background:#efefef;
  margin-bottom: 15px;
}
.EditCakeLine {
  font-size: 17px;
  font-weight: 550;
}
/*---------- 蛋糕已选表格 ----------*/
table {
  border-collapse: collapse;
  text-align: center;
}
table tr {
  border: 1px solid rgb(223, 228, 237);
}
table tr td {
  border: 1px solid rgb(223, 228, 237);
  padding: 0.5rem 0.5rem;
  height: 2.6rem;
  line-height: 1rem;
}
.el-scrollbar {
  padding-bottom: 15px;
}
/*---------- 添加蛋糕样式 -----------*/

.order-message {
  margin-top: 2%;
  // border-bottom: 0.1rem solid #dfe4ed;
  padding-bottom: 2%;
  margin-bottom: 5px;
}
.order-list {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  font-family: Helvetica Neue, Arial, PingFang SC, microsoft yahei, STXihei;
  color: #3f4156;
  box-sizing: inherit;
  margin-top: 10px;
  margin: 0.5rem;
  box-shadow: rgb(223, 228, 237) 2px 2px 10px;
}
.order-list .order-list-item {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  font-family: Helvetica Neue, Arial, PingFang SC, microsoft yahei, STXihei;
  color: #3f4156;
  box-sizing: inherit;
  margin-bottom: 20px;
  border-bottom: 1px solid #fff;
  background: #fff;
}
.order-user-area {
  padding: 10px 20px;
}
.orderfound-header-area .order-header {
  position: relative;
  // height: 50px;
  overflow: hidden;
}
.orderfound-header-area .order-header .order-num {
  display: inline-block;
  position: relative;
  // height: 33px;
  background: #585a6e;
  color: #fff;
  padding: 0 10px;
  text-align: left;
  display: flex;
  align-items: center;
  // margin-top: 10px;
}
.orderfound-header-area .order-header .order-time {
  margin-left: 30px;
}
.orderfound-header-area .order-header .order-num span {
  position: relative;
  z-index: 9;
  font-size: 16px;
  // line-height: 2;
}
.orderfound-header-area .order-header .order-num i {
  display: block;
  position: absolute;
  right: -9px;
  top: 7px;
  width: 18px;
  height: 19px;
  background: #585a6e;
  -webkit-transform: rotate(55deg) skewX(25deg);
  transform: rotate(55deg) skewX(25deg);
  z-index: 0;
}
.order-user-area .user-phone-address .phone-title {
  color: #858692;
}
.price-style {
  color: red;
  margin-right: 5px;
}
.app-container .amap-marker-label .info {
  margin-bottom: 0px;
}
.app-container .amap-marker-label {
  font-size: 12px;
  border: 1px solid blue;
  line-height: 14px;
}
.el-col .el-form-item {
  margin-bottom: 20px!important;
}
.selectTimesubmit {
  display: flex;
  justify-content: center;
  margin-top: -30px;
  margin-left: 50px;
}
.el-form-item__content .el-textarea .el-input__count {
  line-height: 10px;
}
// 去掉输入框textarea的斜杠
.el-form-item .el-form-item__content .el-textarea.el-input--medium textarea {
  resize: none;
}
.selectTime {
  .el-form-item__content {
    display: flex;
  }
}
// 在填充数据之前隐藏
[v-cloak] {
  display: none;
}
</style>
